<?php
namespace App\Http\Controllers\Api;
use App\Model\NewsTable;
use App\Model\JoinTable;
use App\Model\BlockTable;
use App\Model\ServiceTable;
use App\Model\IndustryTable;
use App\Model\LinkTable;
use App\Model\WordTable;
use App\Model\MessageTable;
use App\Repository\Common\ConstTable;
use App\Repository\BaseController\ApiController;
use App\Repository\Sys\JsonRespose;
use App\Repository\Sys\Str;
//web前台接口管理
class WebController extends ApiController{
	//新闻-列表
    public function getNewsList(){
        $page = \Request::get('page',1);
        $limit = \Request::get('page_num',10);
        $title = \Request::get('title');
        $type = \Request::get('type',0);
        $status = \Request::get('status',1);
        return JsonRespose::done(NewsTable::getNewsList($page,$limit,$type,$title,$status));
    }
    //新闻-详情
    public function getNewsInfo(){
        $id = \Request::get('id');
        return JsonRespose::done(NewsTable::getNewsInfo($id));
    }
    //职位-列表
    public function getJoinList(){
        $page = \Request::get('page',1);
        $limit = \Request::get('page_num',10);
        $title = \Request::get('title');
        $status = \Request::get('status',1);
        return JsonRespose::done(JoinTable::getJoinList($page,$limit,$title,$status));
    }
    //职位-详情
    public function getJoinInfo(){
        $id = \Request::get('id');
        return JsonRespose::done(JoinTable::getJoinInfo($id));
    }
	//服务-列表
    public function getServiceList(){
        $page = \Request::get('page', 1);
        $limit = \Request::get('page_num', 10);
        $offset = ($page - 1) * $limit;
        //拼接sql
        $sql_1 = "select * from service as d WHERE d.type=1";
        $sql_2 = "select * from service as d WHERE d.type=2";
        $sql_3 = "select * from service as d WHERE d.type=3";
        $sql_4 = "select * from service as d WHERE d.type=4";
        $sql_5 = "select * from service as d WHERE d.type=5";
        $sql_6 = "select * from service as d WHERE d.type=6";
        //执行sql
        $res_1 = \DB::select($sql_1);
        $res_2 = \DB::select($sql_2);
        $res_3 = \DB::select($sql_3);
        $res_4 = \DB::select($sql_4);
        $res_5 = \DB::select($sql_5);
        $res_6 = \DB::select($sql_6);
        $res = array($res_1,$res_2,$res_3,$res_4,$res_5,$res_6);
        $data=[];
        foreach ($res as $v) {
        	foreach ($v as $vv) {
        		$vv->icon_class=ConstTable::SERVICE_WEB_ICON[$vv->type];
        		$vv->type_text=ConstTable::SERVICE_TYPE[$vv->type];
	        }
        	$data[] = $v;
        }
        return JsonRespose::success([
            'res' => $data
        ]);
    }
    //服务-详情
    public function getServiceInfo(){
        $id = \Request::get('id');
        return JsonRespose::done(ServiceTable::getServiceInfo($id));
    }
    //首页logo墙-列表
    public function getLinkList(){
        $page = \Request::get('page',1);
        $limit = \Request::get('page_num',10);
        $title = \Request::get('title');
        $status = \Request::get('status',1);
        return JsonRespose::done(LinkTable::getLinkList($page,$limit,$title,$status));
    }
    //行业-列表
    public function getIndustryList(){
        $page = \Request::get('page',1);
        $limit = \Request::get('page_num',10);
        $title = \Request::get('title');
        $status = \Request::get('status',1);
        return JsonRespose::done(IndustryTable::getIndustryList($page,$limit,$title,$status));
    }
    //行业-详情
    public function getIndustryInfo(){
        $id = \Request::get('id');
        return JsonRespose::done(IndustryTable::getIndustryInfo($id));
    }
    //在线留言-添加
    public function postMessageAdd(){
        //获取所有参数到$param数组
        $param = \Request::all();
        $data = [
            'name' => $param['name'],
            'email' => $param['email'],
            'phone' => $param['phone'],
            'weixin' => $param['weixin'],
            'content' => $param['content'],
            'created_at' => Str::getNowDateTime(),
        ];
        $res = MessageTable::ORM()->insert($data);
        if ($res) {
            return JsonRespose::success();
        } else {
            return JsonRespose::fail();
        }
    }
	//简历-添加
    public function postWordAdd(){
        //获取所有参数到$param数组
        $param = \Request::all();
        $data = [
            'join_id' => $param['id'],
            'name' => $param['name'],
            'phone' => $param['phone'],
            'word_url' => $param['word_url'],
            'status' => 1,
            'created_at' => Str::getNowDateTime(),
        ];
        $res = WordTable::ORM()->insert($data);
        if ($res) {
            return JsonRespose::success();
        } else {
            return JsonRespose::fail();
        }
    }
    public function getBlock(){
        $group_id = \Request::get('group_id');  //数据组id
        return JsonRespose::done(BlockTable::getBlock($group_id));
    }
}
